import {getCart} from '../../assets/js/request.js'
const state = {
    cartArr:JSON.parse(localStorage.getItem('cartArr')) || [],
}
const mutations = {
    setCartArr(state,data) {
        state.cartArr = data
        console.log(state.cartArr);
    },
    // addNum(index,data) {
    //     cartArr[index].num += data.num;
    //     console.log(state.cartArr);
    // }
}
const actions = {
    async getCartArr({commit}) {
        let data = await getCart();
        console.log(data);
        // console.log(data,1111);
        commit('setCartArr',data)
    }
}
const getters = {
    // afterRequest(state){
    //     if(state.cartArr !== []) {
    //         return this.cartArr
    //     }
    // }
}
export default {
    namespaced: true,
    state,
    mutations,
    actions,
    getters,
}